package com.campus_activity.campus_activity.controller;


import com.campus_activity.campus_activity.common.R;
import com.campus_activity.campus_activity.domain.dto.LoginDTO;
import com.campus_activity.campus_activity.domain.dto.UserDTO;
import com.campus_activity.campus_activity.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author hb
 * @version 17
 */
@Tag(name = "登录接口")
@RestController
@RequestMapping("/login")
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;

    @Operation(summary = "通过手机号-验证码登录")
    @PostMapping("/phone")
    public R<?> loginByPhone(@RequestBody LoginDTO loginDTO) {
        String token = loginService.loginByPhone(loginDTO);
        return R.success(token);
    }

    @Operation(summary = "通过手机号-密码登录")
    @PostMapping("/pwd")
    public R<?> loginByPassword(@RequestBody LoginDTO loginDTO) {
        String token = loginService.loginByPwd(loginDTO);
        return R.success(token);
    }

    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public R<?> register(@RequestBody UserDTO userDTO) {
        loginService.register(userDTO);
        return R.success("用户注册成功");
    }
}
